package net.sharpf2.api.info;

import net.sharpf2.api.Globals;
import net.sharpf2.api.game.Interfaces;

/**
 *
 * @author Piotr Gajdowski
 */
public class Run {
    
    /**
     * Gets the players run energy.
     * @return  int Energy.
    */
    public static int getEnergy() {
        if (Interfaces.isInterfaceValid(750) && Globals.CLIENT.getGamestate() == 11) {
            return (int)Integer.parseInt(Interfaces.get(750, 5).getContent().getText());
        }
        return -1;
    }
        
    /**
     * Checks if player is resting or not.
     * @return  Boolean True if player is resting, otherwise false.
    */
    public static boolean isResting() {
        if (Globals.CLIENT.getSettings().getData()[173] == 1) {
            return true;
        }
        return false;
    }
    
    /**
     * Function to let the player rest for a while.
    */
    public static void rest() {
        if (Interfaces.isInterfaceValid(750) && Globals.CLIENT.getGamestate() == 11) {
            if (Globals.CLIENT.getSettings().getData()[173] != 1) {
                Interfaces.get(750, 1).getActions().click("(Rest|Ausruhen|Repos)");
            }
        }
    }
    
    /**
     * Turns run mode on or off depending on the value of the boolean parameter.
     * @param   onoff   Boolean Set at true if you want to enabled run, otherwise false.
    */
    public static void turnRun(boolean onoff) {
        if (Interfaces.isInterfaceValid(750) && Globals.CLIENT.getGamestate() == 11) {
            if (onoff == true && Globals.CLIENT.getSettings().getData()[173] != 1) {
                Interfaces.get(750, 1).getActions().click();
            } else if (onoff == false && Globals.CLIENT.getSettings().getData()[173] != 0) {
                Interfaces.get(750, 1).getActions().click();
            }
        }
    }
    
    /**
     * Checks if player is currently running
     * @return running
     */
    public static boolean isRunning(){
        return Globals.CLIENT.getSettings().getData()[173] == 1;
    }
    
}
